let fly = new Fly;
//let storage = window.localStorage;
let layerloading;
let oprtype;
let paginglimit = 10;
let paginglimits = [10, 15, 20, 25, 30];

function postJSON(url, data, callbackfunc1, callbackfunc2, callbackfunc3, callbackfuncbef, callbackfuncaft, urlver) {
    let submitData = {};
    submitData['joininstid'] = '00000000';
    submitData['joininstssn'] = '00000000';
    submitData['reqdate'] = '00000000';
    submitData['reqtime'] = '00000000';
    submitData['sign'] = '12345678123456781234567812345678';
    submitData['data'] = data;
    //let msgtoken = storage['msgtoken'];
    //if(msgtoken != undefined){
    //    submitData['msgtoken'] = msgtoken;
    //}

    if (callbackfuncbef != undefined) {
        callbackfuncbef();
    }

    // if(urlver!= undefined){
    //     url = url+urlver;
    // }else{
    //     url = url+'/V1';
    // }


    fly.post(url, submitData).then(function (response) {
        if (callbackfuncaft != undefined) {
            callbackfuncaft();
        }
        console.log(response);
        let data = response.data;

        let result = data['result'];
        let resultdesc = data['resultdesc'];
        if ('0000' == result) {
            // if(data['msgtoken']!= undefined){
            //     storage['msgtoken'] = data['msgtoken'];
            // }
            callbackfunc1(data['data']);
        } else if ('CF988' == result) {
            //session过期
            alert('session过期，即将返回首页');
            window.top.location.href = '/';
        } else {
            if (callbackfunc2 != undefined) {
                callbackfunc2(result, resultdesc);
            } else {

            }
        }
    }).catch(function (error) {
        if (callbackfuncaft != undefined) {
            callbackfuncaft();
        }
        console.log(error);
        if (callbackfunc3 != undefined) {
            callbackfunc3();
        } else {

        }
    });

}

function initSubmitData() {
    var submitData = {};
    submitData['joininstid'] = '00000000';
    submitData['joininstssn'] = '00000000';
    submitData['reqdate'] = '00000000';
    submitData['reqtime'] = '00000000';
    submitData['sign'] = '12345678123456781234567812345678';
    // let msgtoken = storage['msgtoken'];
    // if(msgtoken != undefined){
    //     submitData['msgtoken'] = msgtoken;
    // }
    return submitData;
}

function geneSubmitDataFromForm(element, submitData) {
    var x = $(element).serializeArray();
    if (submitData == undefined) {
        submitData = {};
    }
    $.each(x, function (i, field) {
        submitData[field.name] = field.value;
    });
    if ("undefined" != typeof logonUser) {
        if (logonUser.subunitid != '') {
            if (logonUser.subunitid != '0108') {
                submitData['subunitid'] = logonUser.subunitid;
            }
        }
    }

    return submitData;
}

function initDictForPage(layer, dictTypeList, callbackfunc1) {
    let data = {};
    data['dicttype'] = dictTypeList;

    let url = '/console/access/dict/getDictMapForPage/';
    postJSON(url, data,
        function (data) {
            console.log(data['data']);
            callbackfunc1(data['data']);
        }, function (result, resultdesc) {
            layer.msg('数据字典加载失败，' + result + ':' + resultdesc);
        }, function () {
            layer.msg('数据字典加载失败，其它错误');
        }, function () {
            layerloading = layer.load();
        }, function () {
            layer.close(layerloading);
        });
}

// function parseDataForPagingList(resData){
//     storage['msgtoken'] = resData['msgtoken'];
//     return {
//         "code": resData.result, //解析接口状态
//         "msg": resData.resultdesc, //解析提示文本
//         "count": resData['data'].count, //解析数据长度
//         "data": resData['data'].data //解析数据列表
//     };
// }

